package util;

import java.util.regex.Pattern;

/**
 * Created by shangxzheng on 2014/8/22.
 */
public class RegexUtil {
    public static boolean checkEmailValid(String strEmail){
        if(strEmail!=null) {
            String emailTemp
                    = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
            Pattern pattern = Pattern.compile(emailTemp);
            return pattern
                    .matcher(strEmail).matches();
        }
        return  false;
    }

    /**
     * Check the Phone number user input whether is valid.
     */
    public static boolean checkPhoneNum(String strPhone){
        if(strPhone!=null) {
//            Pattern pattern
//                    = Pattern
//                    .compile("^((13[0-9])|(15[^4,\\D])|(170)|(18[0,5-9])|(14[5,7]))\\d{8}$");
//            return pattern.matcher(strPhone).matches();

            return strPhone.length()==11;
        }
        return false;
    }
    /**
     * Check the Email Address user input whether is valid.
     */
    public static boolean checkEmailAddr(String strEmail){
        if(strEmail!=null) {
            String emailTemp
                    = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
            Pattern pattern = Pattern.compile(emailTemp);
            return pattern
                    .matcher(strEmail).matches();
        }
        return  false;
    }
    /**
     * Check the password user input whether is valid
     * @param strPassword
     * @return true: The password is valid.  false:The password is invalid.
     */
    public static boolean checkPassword(String strPassword){
        if(strPassword!=null) {
            Pattern pattern = Pattern
                    .compile("^([A-Za-z0-9!@#$%^&*.~/{}|()'\\\"?><,.`+-=_:;\\\\\\\\[]]\\\\\\\\\\\\\\[]{6,20})$");
            return pattern
                    .matcher(strPassword).matches();
        }
        return false;
    }
}
